#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution01 {
    int Hash[128] = { 0 };

public:
    int lengthOfLongestSubstring(string s) {

        int left = 0, right = 0;
        int maxlen = INT_MIN;
        int len = s.size();
        while (right < len) {
            Hash[s[right]]++;
            while (Hash[s[right]] > 1) {

                Hash[s[left]]--;
                left++;
            }
            maxlen = max(maxlen, right - left + 1);

            right++;
        }
        return maxlen == INT_MIN ? 0 : maxlen;
    }
};

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int hash[2] = { 0 };
        int left = 0, right = 0, len = nums.size();
        int maxlen = 0;
        while (right < len) {
            hash[nums[right]]++;
            while (hash[0] > k)
                hash[nums[left++]]--;
            maxlen = max(maxlen, right - left + 1);
            right++;
        }
        return maxlen;
    }
};

int main() {
    Solution s;
    vector<int> v({ 1,1,1,0,0,0,1,1,1,1,0 });
    s.longestOnes(v, 2);
	return 0;
}